package ltd.newbee.mall.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ltd.newbee.mall.api.admin.param.QueryAdminPermParam;
import ltd.newbee.mall.api.admin.vo.AdminPermVo;
import ltd.newbee.mall.entity.AdminPerm;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AdminPermMapper extends BaseMapper<AdminPerm> {

    @Select("<script>" +
            "SELECT p.* FROM tb_newbee_mall_perm AS p " +
            "INNER JOIN tb_newbee_mall_perm_user AS pu ON pu.perm_id = p.id " +
            "INNER JOIN tb_newbee_mall_admin_user AS a ON a.admin_user_id = pu.user_id " +
            "INNER JOIN tb_newbee_mall_admin_user_token AS t ON t.admin_user_id = a.admin_user_id " +
            "WHERE t.token = #{token} " +
            "</script>")
    List<AdminPerm> selectAdminUserPermByToken(String token);

    @Select("<script>" +
            "SELECT p.name, p.perm, p.id FROM tb_newbee_mall_perm AS p " +
            "<where>" +
            "<if test=\"query.name != null and query.name != ''\">" +
            "p.name LIKE CONCAT('%', #{query.name}, '%')" +
            "</if>" +
            "</where>" +
            "</script>")
    List<AdminPermVo> selectPageByCondition(@Param("page") Page<AdminPermVo> page, @Param("query") QueryAdminPermParam query);
}
